<?php

$db = new Sektoral();
$table = "sektoral";
$id	=	"";
$order = "idsektoral";
$sektoral = $db->lihat($table, $order, $id);

$o .= '<a href="?page=addsektoral"><i class="icon-plus"></i> Tambah Data</a><br>';
if ($sektoral) {
	if (isset($_GET['success']) && ($_GET['success'] == "1")) {

		$o .= '<div class="alert alert-success">
				Proses hapus sektoral berhasil
				</div>';
				
	} elseif (isset($_GET['success']) && ($_GET['success'] == "0")) {
		
		$o .= '<div class="alert alert-error">
				Proses hapus sektoral gagal
			   </div>';
	}
	$o .= '<table class="table table-striped table-bordered table-condensed">
			<tr>
				<th><center>No</th>
				<th><center>Nama Sektoral</th>
				<th><center>Ikon Sektoral</th>
				<th colspan="3"><center>Tindakan</td>
			</tr>';
	
	$no = 1;
	
	foreach($sektoral as $x) {
		if ($x['icon'] != "") {
			$gambar = '<img src="../file/icon/'.$x['icon'].'">';
		} else {
			$gambar = '<span class="label label-important">belum ada ikon</span>';
		}
		
		$o .= '<tr>
					<td><center>'.$no.'</td>
					<td><center>'.$x['nama_sektoral'].'</td>
					<td><center>'.$gambar.'</td>
					<td><center><a href="?page=listkegiatan&idsektoral='.$x['idsektoral'].'"><i class="icon-zoom-in"></i> Lihat Kegiatan</a></td>
					<td><center><a href="?page=editsektoral&id='.$x['idsektoral'].'"><i class="icon-wrench"></i> Ubah</a></td>
					<td><center><a href="?page=sektoral&action=remove&idsektoral='.$x['idsektoral'].'"><i class="icon-remove"></i> Hapus</a></td>
			  </tr>';
			  
		$no++;
		
	}

	$o .= '</table>';

} else {

	$o .= '<div class="alert alert-error">
		  <center>Data kosong</center>
		  </div>';
} 

echo $o;

if ($_GET['action'] == "remove") {

	$id = htmlentities(mysql_real_escape_string($_GET['idsektoral']));
	
	$hapussektoral = $db->hapus($table,$id);
	
	if ($hapussektoral) {
		?>
			<script language="javascript">
			document.location="?page=sektoral&success=1";
			</script>
		<?php
		
	} else {
		?>
			<script language="javascript">
			document.location="?page=sektoral&success=0";
			</script>
		<?php
	}
}
